﻿using BW.EatRabbit.API.Application.Commands.Provider;
using BW.EatRabbit.Domain;
using BW.EatRabbit.ErrorCode;
using BW.EatRabbit.Infrastructure.Interfaces;
using MediatR;

namespace BW.EatRabbit.API.Application.CommandHandlers.Provider
{
    public class ProviderCreateCommandHandler : IRequestHandler<ProviderCreateCommand, APIResult<int>>
    {
        private readonly IBaseRepository<Provider_Information> _provideRepository;
        public ProviderCreateCommandHandler(IBaseRepository<Provider_Information> provideRepository)
        {
            _provideRepository = provideRepository;

        }
        public Task<APIResult<int>> Handle(ProviderCreateCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            Provider_Information provider = new Provider_Information();
            provider.ProviderType=request.ProviderType;
            provider.ProductionBatch=request.ProductionBatch;
            provider.Creator = request.UserNickname;
            _provideRepository.AddEntity(provider);
            result.Code = ResultCode.添加成功;
            result.Message = ResultCode.添加成功.ToString();

            return Task.FromResult(result);
        }
    }
}
